package com.lanou.zy.projecta.application;

import android.app.Application;
import android.content.Context;

import com.lanou.zy.projecta.greedao.entity.DaoMaster;
import com.lanou.zy.projecta.greedao.entity.DaoSession;

import cn.jpush.android.api.JPushInterface;


/**
 * Created by dllo on 15/10/21.
 */
public class BaseApplication extends Application {

    private static Context context;
    private static DaoMaster daoMaster;
    private static DaoSession daoSession;

    private boolean type;



    @Override
    public void onCreate() {
        super.onCreate();
        JPushInterface.init(this);
        context = this;
//         context = getApplicationContext();
        setType(false);
    }

    public static Context getContext() {

        return context;
    }


    public static DaoMaster getDaoMaster() {
        if (daoMaster == null) {
            DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(context, "lanou", null);
            daoMaster = new DaoMaster(helper.getReadableDatabase());
        }
        return daoMaster;
    }

    public static DaoSession getDaoSession() {
        if (daoSession == null) {
            if (daoMaster == null) {
                getDaoMaster();
                daoSession = daoMaster.newSession();
            }
        }
        return daoSession;
    }

    public boolean isType() {
        return type;
    }

    public void setType(boolean type) {
        this.type = type;
    }

}
